//
//  WrapperMainViewController.m
//  SXH
//
//  Created by 房 国生 on 15/7/15.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "WrapperMainViewController.h"
#import "DWPageControl.h"
#import "ParkEntity.h"
#import "LPEntity.h"
#import "FindEntity.h"
#import "LocalProductDetailViewController.h"
#import "FindViewController.h"
#import "MoreViewController.h"
#import "MeViewController.h"
#import "LocalProductViewController.h"
#import "RecFoundViewController.h"
#import "WrapperViewController.h"
#import "IntroduceViewController.h"
#import "FindDetailViewController.h"
#import "RouteShopViewController.h"
#import "RouteDetailViewController.h"
#import "CityViewController.h"
#import "SearchViewController.h"
#import "FindRecomViewController.h"
#import "FindSpotViewController.h"
#import "WebViewController.h"
#import "Reachability.h"

#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "CommonService.h"
#import "HomeEntity.h"
#import "RouteEntity.h"
#import "LocationManagement.h"
#import "CitySelDelegate.h"
#import "AppDelegate.h"
#import "weatherTableViewCell.h"
#import <MediaPlayer/MediaPlayer.h>

#import "weatherEntity.h"
#import "FirstWeatherEntity.h"
#import "BasicMapAnnotation.h"
#import "BMKClusterManager.h"
#import <QuartzCore/QuartzCore.h>
#import "SpotClusterItem.h"
#import "ParkTableViewController.h"
#import "EnterShareViewController.h"
#import "OfflineManager.h"
#import "HPActivityListViewController.h"
/*
 *点聚合Annotation
 */
@interface ClusterAnnotation : BMKPointAnnotation

///所包含annotation个数
@property (nonatomic, assign) NSInteger size;
@property (nonatomic, strong) NSMutableArray* parksArray;


@end

@implementation ClusterAnnotation
@synthesize size = _size;
@synthesize parksArray=_parksArray;

- (id)init {
    self = [super init];
    if (self) {
        _parksArray = [[NSMutableArray alloc] init];
    }
    return self;
}

@end


/*
 *点聚合AnnotationView
 */
@interface ClusterAnnotationView : BMKPinAnnotationView {
    
}

@property (nonatomic, assign) NSInteger size;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *labelTitle;

@end

@implementation ClusterAnnotationView

@synthesize size = _size;
@synthesize label = _label;
@synthesize labelTitle = _labelTitle;

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setBounds:CGRectMake(0.f, 0.f, 77.f, 77.f)];
        
        UIImageView *borderImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 75, 108)];
        [borderImage setImage:[UIImage imageNamed:@"首页景点图片框.png"]];
        [self addSubview:borderImage];
        
        UILabel *shadow=[[UILabel alloc] initWithFrame:CGRectMake(31.f, 108.f, 14.f, 8.f)];
        shadow.layer.borderWidth = 10;
        shadow.layer.cornerRadius = 4;
        shadow.layer.borderColor = [UIColor grayColor].CGColor;
        shadow.layer.shadowColor = [UIColor blackColor].CGColor;
        shadow.layer.shadowOpacity = 1.0;
        shadow.layer.shadowRadius = 10.0;
        shadow.layer.shadowOffset = CGSizeMake(0, 3);
        shadow.clipsToBounds = NO;
        [self addSubview:shadow];
        
        _label = [[UILabel alloc] initWithFrame:CGRectMake(-5.f, -5.f, 20.f, 20.f)];
        _label.textColor = [UIColor whiteColor];
        [_label.layer setMasksToBounds:YES];
        _label.layer.cornerRadius = 10;
        _label.font = [UIFont systemFontOfSize:11];
        _label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_label];
        
        _labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(2.f, 75.f, 73.f, 20.f)];
        _labelTitle.textColor = [UIColor blackColor];
        _labelTitle.font = [UIFont systemFontOfSize:11];
        _labelTitle.textAlignment = NSTextAlignmentCenter;
        _labelTitle.backgroundColor=[UIColor whiteColor];
        _labelTitle.alpha=1;
        [self addSubview:_labelTitle];
        
        self.alpha = 1;
    }
    return self;
}

- (void)setSize:(NSInteger)size {
    _size = size;
    if (_size == 1) {
        self.label.hidden = YES;
        self.pinColor = BMKPinAnnotationColorRed;
        return;
    }
    self.label.hidden = NO;
    if (size > 20) {
        self.label.backgroundColor = [UIColor redColor];
    }
    else if (size > 10) {
        self.label.backgroundColor = [UIColor purpleColor];
    }
    else if (size > 5) {
        self.label.backgroundColor = [UIColor blueColor];
    }
    else {
        self.label.backgroundColor = [UIColor greenColor];
    }
    self.label.backgroundColor = [UIColor colorWithRed:89/255.0 green:205/255.0 blue:62/255.0 alpha:1];
    _label.text = [NSString stringWithFormat:@"%ld", (long)size];
    _labelTitle.text = @"NULL";
}

@end

@interface WrapperMainViewController ()<UIScrollViewDelegate, UISearchBarDelegate, CitySelDelegate,UITableViewDataSource,UITableViewDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate>
{
    int mPage;
    MJRefreshHeaderView *_header;
    IBOutlet BMKMapView* _mapView;
    BMKClusterManager *_clusterManager;//点聚合管理类
    NSInteger _clusterZoom;//聚合级别
    NSMutableArray *_clusterCaches;//点聚合缓存标注
    BOOL setMapCenter;//设置景点为在地图中心显示
    int mapZoomLevel;//地图缩放层级
    BOOL GPSLocation;//GPS 定位
    BOOL cityChangeFlag;//城市切换
    BMKLocationService*_locService;
    NSString *_city_id;
}

@property (weak, nonatomic) IBOutlet UITableView *tableViewWeather;
@property (nonatomic, strong) IBOutlet UIScrollView *scrollViewMain;
@property (nonatomic, strong) IBOutlet UIView *viewMain;
@property (nonatomic, strong) IBOutlet UIScrollView *menuScrollView;
@property (nonatomic, strong) DWPageControl *pageControlMenu;

@property (nonatomic, strong) FindRecomViewController *findRecomVC;
@property (nonatomic, strong) FindViewController *findVC;
@property (nonatomic, strong) MoreViewController *moreVC;
@property (nonatomic, strong) MeViewController *meVC;
@property (nonatomic, strong) IBOutlet UIButton *btnHome;
@property (nonatomic, strong) IBOutlet UIButton *btnFind;
@property (nonatomic, strong) IBOutlet UIButton *btnMe;
@property (nonatomic, strong) IBOutlet UIButton *btnMore;
@property (nonatomic, strong) IBOutlet UILabel *labelHome;
@property (nonatomic, strong) IBOutlet UILabel *labelFind;
@property (nonatomic, strong) IBOutlet UILabel *labelMe;
@property (nonatomic, strong) IBOutlet UILabel *labelMore;

@property (nonatomic, strong) IBOutlet UIButton *btnCity;
@property (nonatomic, strong) IBOutlet UILabel *labelCity;
@property (nonatomic, strong) IBOutlet UIButton *btnWeather;
@property (nonatomic, strong) IBOutlet UIButton *leftSign;
@property (nonatomic, strong) IBOutlet UIView *searchView;


@property (nonatomic, strong) IBOutlet UIButton *btnSearchBar;
@property (nonatomic, strong) HomeEntity *homeEntity;
@property (nonatomic, strong) NSMutableArray *mutableArrayButton;
@property (nonatomic, strong) IBOutlet UIView *pageDotView;

//@property (nonatomic, strong) NSString *strWeather;
@property (nonatomic, strong) NSString *strWeatherOut;
@property (strong, nonatomic) IBOutlet UIView *weatherTableView;
@property (strong, nonatomic) IBOutlet UIView *blackAlpha;
@property (nonatomic, strong) weatherEntity * today;
@property (nonatomic, strong) FirstWeatherEntity * nextDays;
@property (nonatomic, strong) NSArray *forecast;
@property (nonatomic,strong) BMKUserLocation *autoLocation;

@end

#define K_cellIdentifier   @"weatherTableViewCell"


@implementation WrapperMainViewController

@synthesize scrollViewMain, viewMain, menuScrollView;
@synthesize pageControlMenu, findRecomVC;
@synthesize findVC, moreVC, meVC, searchView, btnSearchBar;
@synthesize btnFind, btnHome, btnMe, btnMore, labelFind, labelHome, labelMe, labelMore;
@synthesize btnCity, labelCity, btnWeather, leftSign;
@synthesize homeEntity, cityEntity, mutableArrayButton, viewNavigation, pageDotView;
@synthesize dicPushMessage;
@synthesize weatherTableView,blackAlpha,today,forecast,nextDays,tableViewWeather;

//@synthesize weatherDate,weatherImage,weatherWeek;
- (void)viewDidLoad {
    [super viewDidLoad];
    GPSLocation = NO;
    _autoLocation = [[BMKUserLocation alloc]init];
    _locService = [[BMKLocationService alloc]init];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _locService.delegate = self;
    [_locService startUserLocationService];
    
    self.btnSearchBar.layer.cornerRadius = 4;
    // Do any additional setup after loading the view from its nib.
    //[super.navigationController setNavigationBarHidden:NO animated:FALSE];
//    [self.navigationController setNavigationBarHidden:YES];
//    viewMain = [UIView autoLayoutView];
    
//    [self.scrollViewMain addSubview:viewMain];
    [self.scrollViewMain setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height - 106)];

    mutableArrayButton = [[NSMutableArray alloc] init];
    
    [self addHeader];
    
    labelCity.text = [[AppDelegate instance].dicCurrentCity valueForKeyPath:@"cname"];
    labelCity.textAlignment = NSTextAlignmentCenter;
    //[btnCity setTitle:[[AppDelegate instance].dicCurrentCity valueForKeyPath:@"cname"] forState:UIControlStateNormal];
    
    [[LocationManagement sharedInstance] startGPS];
    [LocationManagement sharedInstance].delegate = self;
    
    //[super getAPPVersion:NO AppId:@"1"];
    
    UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(disappear)];
    [blackAlpha addGestureRecognizer:click];
    blackAlpha.frame = CGRectMake(0, SCREEN_HEIGHT, self.view.bounds.size.width, self.view.bounds.size.height);
    
    [self.view addSubview:blackAlpha];
    
    weatherTableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200);
    
    [self.view addSubview:weatherTableView];
    
    if (iPhone4s) {
        scrollViewMain.contentSize = CGSizeMake(scrollViewMain.contentSize.width, 548);
    }
    
    _clusterCaches = [[NSMutableArray alloc] init];
    for (NSInteger i = 3; i < 21; i++) {
        [_clusterCaches addObject:[NSMutableArray array]];
    }
    //点聚合管理类（初始化）
    _clusterManager = [[BMKClusterManager alloc] init];
    self.isAllPark = YES;
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        //        ALERT_ERR_MSG(@"使用地图功能需打开定位服务");
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"使用地图功能需打开定位服务" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
        [alert show];
        alert.tag = 10001;
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self shareCopy];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//static NSInteger const numberPerLine = 4;

- (void)initScrollView:(int)pageCount {

    if (pageControlMenu != nil) {
        [pageControlMenu removeFromSuperview];
        pageControlMenu = nil;
    }
    
    float pageControlWidth = (pageCount-2)*10.0f+40.f;
    float pagecontrolHeight = 10.0f;
    
    NSLog(@"%f,%f",(self.scrollViewMain.frame.size.width/2-pageControlWidth/2), self.menuScrollView.bounds.size.height-33);
    pageControlMenu = [[DWPageControl alloc]initWithFrame:CGRectMake((self.scrollViewMain.frame.size.width/2-pageControlWidth/2),0, pageControlWidth, pagecontrolHeight)];
    [pageControlMenu addTarget:self action:@selector(changePage2:) forControlEvents:UIControlEventValueChanged];
    
    [pageDotView addSubview:pageControlMenu];
    [self.viewMain addSubview:pageDotView];
    [self.scrollViewMain bringSubviewToFront:pageDotView];
    pageControlMenu.numberOfPages = pageCount;
    pageControlMenu.currentPage = (int)(menuScrollView.contentOffset.x / menuScrollView.frame.size.width);
    
    [menuScrollView setDelegate:self];
    [menuScrollView setScrollEnabled:YES];
    [menuScrollView setPagingEnabled:YES];
    menuScrollView.showsHorizontalScrollIndicator = NO;
    menuScrollView.showsVerticalScrollIndicator = NO;
}

- (void)changePage2:(id)sender {
    NSInteger page = pageControlMenu.currentPage;
    // update the scroll view to the appropriate page
    CGRect frame = menuScrollView.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    [menuScrollView setContentOffset:CGPointMake(frame.size.width * page, -64)];
}

- (void) getHomeData:(NSString *) cityId RefreshView:refreshView {
    
    NSString *last_latitude = [[NSUserDefaults standardUserDefaults] valueForKey:@"last_latitude"];
    NSString *last_longitude = [[NSUserDefaults standardUserDefaults] valueForKey:@"last_longitude"];
    
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    /**
     *  如果网络不可用,则从本地加载
     */
    if (status == NotReachable) {
        NSMutableDictionary *dict = [OfflineManager getoutDictDataWithName:@"WarpperMainViewControllerHome"];
        if (dict != nil && dict.allKeys.count > 0) {
            [self dealDataWithDict:dict];
        }
    }
    
    CommonService *service = [[CommonService alloc] init];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           cityId, @"cityid",
                           last_latitude, @"latitude",
                           last_longitude, @"longitude",nil];
    
    [service getNetWorkData:param
                       Path:HOME
                  Successed:^(id entity) {
                      NSMutableDictionary *dic = (NSMutableDictionary *)entity;
                      /**
                       *  保存数据到本地
                       */
                      [OfflineManager saveOfflineDataWithDict:dic andName:@"WarpperMainViewControllerHome"];
                      [self dealDataWithDict:dic];
                      
//                      homeEntity = [[HomeEntity alloc] init];
//                      homeEntity = [homeEntity initWithAttributes:dic];
//                      
//                      dispatch_async(dispatch_get_main_queue(), ^{
//                          for (int i = 0; i < [mutableArrayButton count]; i++) {
//                              UIView *view = [mutableArrayButton objectAtIndex:i];
//                              [view removeFromSuperview];
//                              view = nil;
//                          }
//                          [self setParkElements:homeEntity.mutableArrayPark];
//                          [self setRouteElements:homeEntity.mutableArrayRoute];
//                          [self setFindElements:homeEntity.mutableArrayFind];
//                          [self setLPElements:homeEntity.mutableArrayLP];
//                          
//                          [_clusterManager clearClusterItems];//清除点聚合元素
//                          
//                          if([homeEntity.mutableArrayPark count]>0){
//                              setMapCenter=YES;
////                              ParkEntity *entity = homeEntity.mutableArrayPark[0];
////                              CLLocation *location = [[CLLocation alloc] initWithLatitude:[entity.latitude doubleValue] longitude:[entity.longitude doubleValue]];
////                              [_mapView setCenterCoordinate:location.coordinate animated:YES];
//                              mapZoomLevel=14;
//                              [self updateClusters];
//                              
//                              for(int i=0;i<[homeEntity.mutableArrayPark count];i++){
//                                  ParkEntity *entity = homeEntity.mutableArrayPark[i];
//                                  SpotClusterItem *clusterItem = [[SpotClusterItem alloc] init];
//                                  clusterItem.coor = CLLocationCoordinate2DMake([entity.latitude floatValue],[entity.longitude floatValue]);
//                                  clusterItem.name = entity.title;
//                                  clusterItem.star = entity.star;
//                                  clusterItem.level = entity.level;
//                                  clusterItem.album_thumb = entity.album_thumb;
//                                  clusterItem.parkID = entity.ID;
//                                  clusterItem.is_business = entity.is_business;
//                                  [_clusterManager addClusterItem:clusterItem];
//                              }
//                          }
//                      });
                      [refreshView endRefreshing];
                  } Failed:^(NSInteger errorCode, NSString *message) {
                  }];
}

/**
 *  处理数据
 */
- (void)dealDataWithDict:(NSDictionary *)dict {
    homeEntity = [[HomeEntity alloc] init];
    homeEntity = [homeEntity initWithAttributes:dict];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        for (int i = 0; i < [mutableArrayButton count]; i++) {
            UIView *view = [mutableArrayButton objectAtIndex:i];
            [view removeFromSuperview];
            view = nil;
        }
        [self setParkElements:homeEntity.mutableArrayPark];
        [self setRouteElements:homeEntity.mutableArrayRoute];
        [self setFindElements:homeEntity.mutableArrayFind];
        [self setLPElements:homeEntity.mutableArrayLP];
        
        [_clusterManager clearClusterItems];//清除点聚合元素
        
        if([homeEntity.mutableArrayPark count]>0){
            setMapCenter=YES;
            //                              ParkEntity *entity = homeEntity.mutableArrayPark[0];
            //                              CLLocation *location = [[CLLocation alloc] initWithLatitude:[entity.latitude doubleValue] longitude:[entity.longitude doubleValue]];
            //                              [_mapView setCenterCoordinate:location.coordinate animated:YES];
            mapZoomLevel=14;
            [self updateClusters];
            
            for(int i=0;i<[homeEntity.mutableArrayPark count];i++){
                ParkEntity *entity = homeEntity.mutableArrayPark[i];
                SpotClusterItem *clusterItem = [[SpotClusterItem alloc] init];
                clusterItem.coor = CLLocationCoordinate2DMake([entity.latitude floatValue],[entity.longitude floatValue]);
                clusterItem.name = entity.title;
                clusterItem.star = entity.star;
                clusterItem.level = entity.level;
                clusterItem.album_thumb = entity.album_thumb;
                clusterItem.parkID = entity.ID;
                clusterItem.is_business = entity.is_business;
                [_clusterManager addClusterItem:clusterItem];
            }
        }
    });
}

//获取国家森林公园
- (IBAction)getParkClass:(id)sender {
    self.isAllPark = !self.isAllPark;
    if (self.isAllPark)
    {
        GPSLocation = YES;
        //删除标注
//        NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
//        [_mapView removeAnnotations:array];
//        [_clusterCaches removeAllObjects];
//        for (NSInteger i = 3; i < 21; i++) {
//            [_clusterCaches addObject:[NSMutableArray array]];
//        }
//        [homeEntity.mutableArrayPark removeAllObjects];
//        [homeEntity.mutableArrayFind removeAllObjects];
//        [homeEntity.mutableArrayLP removeAllObjects];
//        [homeEntity.mutableArrayRoute removeAllObjects];
        [self.parkChangeBtn setBackgroundImage:[UIImage imageNamed:@"allparks"] forState:UIControlStateNormal];
//        [self dealDataWithDict:[OfflineManager getoutDictDataWithName:@"WarpperMainViewControllerHome"]];
        [self citySelAction:[AppDelegate instance].dicCurrentCity];
    }
    else
    {
        [self.parkChangeBtn setBackgroundImage:[UIImage imageNamed:@"senlin"] forState:UIControlStateNormal];
        GPSLocation = NO;
        //删除标注
        NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
        [_mapView removeAnnotations:array];
        [_clusterCaches removeAllObjects];
        for (NSInteger i = 3; i < 21; i++) {
            [_clusterCaches addObject:[NSMutableArray array]];
        }
        [homeEntity.mutableArrayPark removeAllObjects];
        [homeEntity.mutableArrayFind removeAllObjects];
        [homeEntity.mutableArrayLP removeAllObjects];
        [homeEntity.mutableArrayRoute removeAllObjects];
        
        [self getParkClassData];
    }

}

- (void) getParkClassData {
    CommonService *service = [[CommonService alloc] init];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"1", @"park_class",
                           _city_id,@"city_id",
                           @"1", @"page",
                           @"999", @"limit",nil];
    /**
     *  如果网络不可用,则从本地加载
     */
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    if (status == NotReachable) {
        NSMutableDictionary *dict = [OfflineManager getoutDictDataWithName:@"WarpperMainViewControllerHome"];
        if (dict != nil && dict.allKeys.count > 0) {
            [self dealDataWithDict:dict];
        }
        return;
    }
    
    
    
    [service getNetWorkData:param
                       Path:PARKCLASS_ENTITY_PATH
                  Successed:^(id entity) {
                      NSMutableDictionary *dic = (NSMutableDictionary *)entity;
                      
                      /**
                       *  保存数据到本地
                       */
                      [OfflineManager saveOfflineDataWithDict:dic andName:@"WarpperMainViewControllerHome"];
                      [self dealDataWithDict:dic];
                      
                  } Failed:^(NSInteger errorCode, NSString *message) {
                  }];
}

- (void)getWeatherData:(NSString *)cityName {
    
    CommonService *service = [[CommonService alloc] init];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           cityName, @"cityname", nil];
    
    [service getNetWorkData:param
                       Path:WEATHER_CITY
                  Successed:^(id entity) {
                      NSDictionary *dic = (NSDictionary *)entity;
                      
                      if ([dic isKindOfClass:[NSDictionary class]] == YES) { //解决天气有时候返回乱码问题
                          NSDictionary *res = [dic valueForKeyPath:@"retData"];
                          
                          forecast = [res valueForKey:@"forecast"];
                          NSDictionary * todayDict =[res valueForKeyPath:@"today"];
                          
                          today =[[weatherEntity alloc]initWithAttributes:todayDict];
//                          _strWeather = [NSString stringWithFormat:@"%@%@", IMAGE_URL, today.todayImage];
                          _strWeatherOut = [NSString stringWithFormat:@"%@%@", IMAGE_URL, today.todayImageOut];
//                          [btnWeather sd_setImageWithURL:[NSURL URLWithString:_strWeatherOut] forState:UIControlStateNormal];
                          [btnWeather setImage:[UIImage imageNamed:@"activity_recommand"] forState:UIControlStateNormal];
                          dispatch_async(dispatch_get_main_queue(), ^{
                              [tableViewWeather reloadData];
                          });
                      }
                  } Failed:^(NSInteger errorCode, NSString *message) {
                      NSLog(@"===");
                  }];
}

- (void)setRouteElements:(NSArray *)elements {
    
    //CGRect rect = CGRectZero;
    CGFloat width = 72;
    CGFloat height = 65;
    
    //rect.size.width = width;
    //rect.size.height = height;
    
    NSInteger count = [elements count];
    for (int i = 0; i < 4 && i < count; i++) {
        ParkEntity *entity = elements[i];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [button sd_setImageWithURL:[NSURL URLWithString:entity.album_thumb] forState:UIControlStateNormal];
        
        
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 5, 0)];
        [button.layer setBorderColor:[UIColor whiteColor].CGColor];
        [button addTarget:self action:@selector(routeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundColor:[UIColor clearColor]];
        //        [button.layer setBorderWidth:.5];
        [button setTag:i];
        
        button.frame = CGRectMake(i * width + (ScreenWidth -288)/5*(i+1) , 193, width, height);
        
        [mutableArrayButton addObject:button];
        [self.scrollViewMain addSubview:button];
    }
}

/**
 *  保存图片到本地
 */
- (void)imageSavedToCache:(UIImage *)image andImageName:(NSString *)imageName {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *cachePath = [NSString stringWithFormat:@"%@/cityImage",NSHomeDirectory()];
    BOOL isCreated = [fileManager fileExistsAtPath:cachePath];
    /**
     *  创建目录,并保存图片
     */
    if (isCreated) {
        NSString *path = [NSString stringWithFormat:@"%@/%@",cachePath,imageName];
        NSData *data = UIImageJPEGRepresentation(image, 1.0);
//        BOOL result = [data writeToFile:path options:NSAtomicWrite error:nil];
        [data writeToFile:path atomically:YES];
    }
}

/**
 *  从本地获取图片
 */
- (UIImage *)imageGetFromCacheWithImageName:(NSString *)imageName {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *cachePath = [NSString stringWithFormat:@"%@/cityImage",NSHomeDirectory()];
    BOOL isCreated = [fileManager fileExistsAtPath:cachePath];
    if (isCreated) {
        NSData *imageData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",cachePath,imageName]];
        UIImage *image = [UIImage imageWithData:imageData];
        return image;
    }
    return nil;
}

- (void)setFindElements:(NSArray *)elements {

    CGFloat width = 72;
    CGFloat height = 65;
    
    NSInteger count = [elements count];
    for (int i = 0; i < 4 && i < count; i++) {
        ParkEntity *entity = elements[i];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [button sd_setImageWithURL:[NSURL URLWithString:entity.album_thumb] forState:UIControlStateNormal];
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 5, 0)];
        [button.layer setBorderColor:[UIColor whiteColor].CGColor];
        [button addTarget:self action:@selector(findButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundColor:[UIColor clearColor]];
        //        [button.layer setBorderWidth:.5];
        [button setTag:i];
        
        button.frame = CGRectMake(i * width + (ScreenWidth -288)/5*(i+1) , 292, width, height);
        
        [mutableArrayButton addObject:button];
        [self.scrollViewMain addSubview:button];
    }
}

- (void)setLPElements:(NSArray *)elements {
    
    CGRect rect = CGRectZero;
    CGFloat width = 72;
    CGFloat height = 65;
    rect.size.width = width;
    rect.size.height = height;
    
    NSInteger count = [elements count];
    for (int i = 0; i < 4 && i < count; i++) {
        ParkEntity *entity = elements[i];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [button sd_setImageWithURL:[NSURL URLWithString:entity.album_thumb] forState:UIControlStateNormal];
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 5, 0)];
        [button.layer setBorderColor:[UIColor whiteColor].CGColor];
        [button addTarget:self action:@selector(lpButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundColor:[UIColor clearColor]];
        //        [button.layer setBorderWidth:.5];
        [button setTag:i];
        
        button.frame = CGRectMake(i * width + (ScreenWidth -288)/5*(i+1)  , 388, width, height);
        [mutableArrayButton addObject:button];
        
        [self.scrollViewMain addSubview:button];
    }
}

- (void)setParkElements:(NSArray *)elements {
    if ([elements count] == 0) {
        return;
    }
    NSInteger numberPerLine = 5;
//    if ([UIScreen mainScreen].bounds.size.width > 320) {
//        numberPerLine = 5;
//    }
    NSInteger numberOfLine = 1;
    NSInteger count = [elements count];
    if (count > numberPerLine) {
        if (count % numberPerLine == 0) {
            numberOfLine = count / numberPerLine;
        }
        else {
            numberOfLine = count / numberPerLine + 1;
        }
    }
    else {
        numberOfLine = 1;
    }
    NSInteger page = 1;
    if (numberOfLine  > 2) {
        if (count % (numberPerLine * 2) == 0) {
            page = count / (numberPerLine * 2);
        }
        else {
            page = (count / (numberPerLine * 2)) + 1;
        }
    }
    [pageControlMenu setNumberOfPages:page];
    CGRect rect = CGRectZero;
    CGFloat width = 240/ numberPerLine;
    CGFloat distance = (SCREEN_WIDTH - 240)/6;
    CGFloat height = width;
    rect.size.width = width;
    rect.size.height = height;
    NSInteger index = 0;
    NSInteger line = 0;
    NSInteger currentPage = 0;
    
    
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *cachePath = [NSString stringWithFormat:@"%@/cityImage",NSHomeDirectory()];
    BOOL isCreated = [fileManager fileExistsAtPath:cachePath];
    
    if (!isCreated) {
        [fileManager createDirectoryAtPath:cachePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    else if (status != NotReachable && isCreated) {
        [fileManager removeItemAtPath:cachePath error:nil];
        [fileManager createDirectoryAtPath:cachePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    for (int i = 0; i < count;) {
        ParkEntity *entity = elements[i];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [button sd_setImageWithURL:[NSURL URLWithString:entity.album_thumb] forState:UIControlStateNormal];
        /**
         *  如果网络可用,则保存图片到本地
         */
        if (status != NotReachable) {
            [self.buttonArr addObject:button];
            [self.imageNameArr addObject:entity.album_thumb.lastPathComponent];
//            [self imageSavedToCache:[button imageForState:UIControlStateNormal] andImageName:entity.album_thumb.lastPathComponent];
        }
        
        
        /**
         *  否则从本地取
         */
        else {
            UIImage *image = [self imageGetFromCacheWithImageName:entity.album_thumb.lastPathComponent];
            [button setImage:image forState:UIControlStateNormal];
        }
        
        //[button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 5, 0)];
        [button.layer setBorderColor:[UIColor whiteColor].CGColor];
        [button addTarget:self action:@selector(menuButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundColor:[UIColor clearColor]];
        //        [button.layer setBorderWidth:.5];
        [button setTag:i];
        
        [button.layer setMasksToBounds:YES];
        [button.layer setCornerRadius:width/2]; //设置矩形四个圆角半径
        
        if (i % numberPerLine == 0 && i != 0) {
            rect.origin.x = index * width;
            index = 0;
            line++;
            if (i % (numberPerLine * 2) == 0 & i != 0) {
                index = 0;
                line = 0;
                currentPage++;
            }
        }
        else {
            if (i != 0) {
                index++;
            }
        }
        
        button.frame = CGRectMake(index * width + distance*(index+1) + currentPage * SCREEN_WIDTH , (width * line) + line*16 + 8, width, width);
        DebugLog(@"%f, %f, %ld", index * width + 13*(index+1) + currentPage * numberPerLine * (width+distance), width, (long)currentPage);
        
        UILabel *labelTitleBottom = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.origin.x - 8, button.frame.origin.y + button.frame.size.height + 2, button.frame.size.width + 15, 12)];
        labelTitleBottom.textColor = [UIColor blackColor];
        labelTitleBottom.font = [UIFont systemFontOfSize:11.0f];
        labelTitleBottom.textAlignment = NSTextAlignmentCenter;
        labelTitleBottom.backgroundColor = [UIColor clearColor];
        [menuScrollView addSubview:labelTitleBottom];
        
        labelTitleBottom.text = entity.title;
        
        [mutableArrayButton addObject:button];
        [mutableArrayButton addObject:labelTitleBottom];
        
        [menuScrollView addSubview:button];
        i++;
    }
    menuScrollView.contentSize = CGSizeMake(menuScrollView.frame.size.width * page, 0);
    
    [self initScrollView:(int)page];
}

- (void)menuButtonClicked:(id)sender {
    UIButton *btn = (UIButton *)sender;
    ParkEntity *entity = [homeEntity.mutableArrayPark objectAtIndex:btn.tag];
    if ([entity.is_business isEqualToString:@"0"] == YES) {
        IntroduceViewController *vc = [[IntroduceViewController alloc] init];
        vc.parkId = [NSString stringWithFormat:@"%@",entity.ID];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else {
        WrapperViewController *vc = [[WrapperViewController alloc] init];
        vc.parkEntity = entity;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)lpButtonClicked:(id)sender {
    UIButton *btn = (UIButton *)sender;
    LPEntity *entity = [homeEntity.mutableArrayLP objectAtIndex:btn.tag];
    LocalProductDetailViewController *vc = [[LocalProductDetailViewController alloc] init];
    vc.wrapEntity = entity;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)findButtonClicked:(id)sender {
    UIButton *btn = (UIButton *)sender;
    FindEntity *entity = [[FindEntity alloc] init];
    
    ParkEntity *parkEntity = [homeEntity.mutableArrayFind objectAtIndex:btn.tag];
    FindDetailViewController *vc = [[FindDetailViewController alloc] init];
    entity.ID = parkEntity.ID;
    vc.findEntity = entity;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)routeButtonClicked:(id)sender {
    UIButton *btn = (UIButton *)sender;
    RouteEntity *entity = [[RouteEntity alloc] init];
    
    ParkEntity *routeEntity = [homeEntity.mutableArrayRoute objectAtIndex:btn.tag];
    RouteDetailViewController *vc = [[RouteDetailViewController alloc] init];
    entity.t_id = routeEntity.ID;
    vc.routeEntity = entity;
    [self.navigationController pushViewController:vc animated:YES];
}

//- (void) initNavigateionBar {
//    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
//        // Load resources for iOS 6.1 or earlier
//        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.56 green:0.76 blue:0.12 alpha:1];
//    } else {
//        // Load resources for iOS 7 or later
//        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.56 green:0.76 blue:0.12 alpha:1];
//    }
//
//    btnCity =[[UIButton alloc] initWithFrame:CGRectMake(6, 0, 41, 32)];
//    [btnCity setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    btnCity.titleLabel.font = [UIFont systemFontOfSize:14.0f];
//    btnCity.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//    [btnCity setTitle:@"扬州" forState:UIControlStateNormal];
//    
//    leftSign =[[UIButton alloc] initWithFrame:CGRectMake(42, 12, 11, 11)];
//    [leftSign setBackgroundImage:[UIImage imageNamed:@"外壳_06"] forState:UIControlStateNormal];
//    
//    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 25, 50.0f, 31)];
//    leftView.backgroundColor = [UIColor clearColor];
//    [leftView addSubview:btnCity];
//    [leftView addSubview:leftSign];
//    
//    [leftSign addTarget:self action:@selector(cityAction:) forControlEvents:UIControlEventTouchUpInside];
//    [btnCity addTarget:self action:@selector(cityAction:) forControlEvents:UIControlEventTouchUpInside];
//
//    
//    btnWeather =[[UIButton alloc] initWithFrame:CGRectMake(280, 25, 32, 32)];
//    [btnWeather setBackgroundImage:[UIImage imageNamed:@"多云@2x"] forState:UIControlStateNormal];
//    [btnWeather addTarget:self action:@selector(weatherAction:) forControlEvents:UIControlEventTouchUpInside];
//    
    //导航条的搜索条
//    btnSearchBar = [[UIButton alloc]initWithFrame:CGRectMake(0.0f,0.0f,200.0f,31.0f)];
//    [btnSearchBar addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
//    [btnSearchBar setBackgroundImage:[UIImage imageNamed:@"title_search@2x"] forState:UIControlStateNormal];
//    //将搜索条放在一个UIView上
//    searchView = [[UIView alloc]initWithFrame:CGRectMake(70, 25, 190.0f, 31)];
//    searchView.backgroundColor = [UIColor clearColor];
//    [searchView addSubview:btnSearchBar];
//
//    NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"关注",@"推荐",nil];
//    //初始化UISegmentedControl
//    segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
//    segmentedControl.frame = CGRectMake(20.0, 0.0, 160.0, 31.0);
//    segmentedControl.selectedSegmentIndex = 0;//设置默认选择项索引
//    segmentedControl.tintColor = [UIColor whiteColor];
//    //有基本四种样式
//    segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;//设置样式
//    [segmentedControl addTarget:self action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged];  //添加委托方法
//    segmentedControl.hidden = YES;
//    [searchView addSubview:segmentedControl];
//    
//    labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(0.0f,0.0f,200.0f,31.0f)];
//    labelTitle.textAlignment = NSTextAlignmentCenter;
//    labelTitle.font = [UIFont boldSystemFontOfSize:18.0];
//    labelTitle.textColor = [UIColor whiteColor];
//    [searchView addSubview:labelTitle];
//    labelTitle.hidden = YES;
//    
//    [viewNavigation addSubview:leftView];
//    [viewNavigation addSubview:searchView];
//    [viewNavigation addSubview:btnWeather];
//}

- (void)showSelectCity:(id)sender {
    
}

- (IBAction)searchAction:(id)sender {
    SearchViewController *vc = [[SearchViewController alloc] init];
    vc.wrapperMainVC = self;
    [self.navigationController pushViewController:vc animated:YES];
}
//
//- (IBAction)doShowHomeVC:(id)sender {
//    [self showMainView:0];
//}
//
//- (IBAction)doShowFindVC:(id)sender {
//    [self showMainView:1];
//}
//
//- (IBAction)doShowMeVC:(id)sender {
//    [self showMainView:2];
//}
//
//- (IBAction)doShowMoreVC:(id)sender {
//    [self showMainView:3];
//}

//- (void) showMainView:(int) page {
//    mPage = page;
//    [btnWeather setBackgroundImage:[UIImage imageNamed:@"多云@2x"] forState:UIControlStateNormal];
//    btnCity.hidden = NO;
//    labelCity.hidden = NO;
//    leftSign.hidden = NO;
//    btnSearchBar.hidden = NO;
//    searchView.hidden = NO;
//    btnWeather.hidden = NO;
//    segmentedControl.hidden = YES;
//    labelTitle.hidden = YES;
//    
//    if (page == 0) {
//        self.scrollViewMain.hidden = NO;
//        findRecomVC.view.hidden = YES;
//        findVC.view.hidden = YES;
//        meVC.view.hidden = YES;
//        moreVC.view.hidden = YES;
////        self.title = @"瘦西湖";
//        
//        [btnHome setBackgroundImage:[UIImage imageNamed:@"首页_01"] forState:UIControlStateNormal];
//        [btnFind setBackgroundImage:[UIImage imageNamed:@"发现_02"] forState:UIControlStateNormal];
//        [btnMe setBackgroundImage:[UIImage imageNamed:@"我_02"] forState:UIControlStateNormal];
//        [btnMore setBackgroundImage:[UIImage imageNamed:@"更多_02"] forState:UIControlStateNormal];
//        
//        labelHome.textColor = [UIColor colorWithRed:0.55 green:0.77 blue:0.2 alpha:1];
//        labelFind.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMe.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMore.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        
//        [btnWeather sd_setBackgroundImageWithURL:[NSURL URLWithString:_strWeather] forState:UIControlStateNormal];
//    } else if (page == 1) {
//        self.scrollViewMain.hidden = YES;
//        findVC.view.hidden = NO;
//        findRecomVC.view.hidden = YES;
//        meVC.view.hidden = YES;
//        segmentedControl.hidden = NO;
//        
//        moreVC.view.hidden = YES;
//        
//        self.title = @"发现";
//        
//        [btnHome setBackgroundImage:[UIImage imageNamed:@"首页_02"] forState:UIControlStateNormal];
//        [btnFind setBackgroundImage:[UIImage imageNamed:@"发现_01"] forState:UIControlStateNormal];
//        [btnMe setBackgroundImage:[UIImage imageNamed:@"我_02"] forState:UIControlStateNormal];
//        [btnMore setBackgroundImage:[UIImage imageNamed:@"更多_02"] forState:UIControlStateNormal];
//        
//        labelHome.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelFind.textColor = [UIColor colorWithRed:0.55 green:0.77 blue:0.2 alpha:1];
//        labelMe.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMore.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        
//        [btnWeather setBackgroundImage:[UIImage imageNamed:@"发现_01-白@2x"] forState:UIControlStateNormal];
//        btnCity.hidden = YES;
//        labelCity.hidden = YES;
//        leftSign.hidden = YES;
//        btnSearchBar.hidden = YES;
//    } else if (page == 2) {
//        self.scrollViewMain.hidden = YES;
//        findVC.view.hidden = YES;
//        meVC.view.hidden = NO;
//        moreVC.view.hidden = YES;
//        btnSearchBar.hidden = YES;
//        leftSign.hidden = YES;
//        btnWeather.hidden = YES;
//        btnCity.hidden = YES;
//        labelCity.hidden = YES;
//        labelTitle.hidden = NO;
//        labelTitle.text = @"我的";
//        
//        segmentedControl.selectedSegmentIndex = 0;
//        [btnHome setBackgroundImage:[UIImage imageNamed:@"首页_02"] forState:UIControlStateNormal];
//        [btnFind setBackgroundImage:[UIImage imageNamed:@"发现_02"] forState:UIControlStateNormal];
//        [btnMe setBackgroundImage:[UIImage imageNamed:@"我_01"] forState:UIControlStateNormal];
//        [btnMore setBackgroundImage:[UIImage imageNamed:@"更多_02"] forState:UIControlStateNormal];
//        
//        labelHome.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelFind.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMe.textColor = [UIColor colorWithRed:0.55 green:0.77 blue:0.2 alpha:1];
//        labelMore.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        
//    } else if (page == 3) {
//        self.scrollViewMain.hidden = YES;
//        findVC.view.hidden = YES;
//        meVC.view.hidden = YES;
//        moreVC.view.hidden = NO;
//        btnSearchBar.hidden = YES;
//        leftSign.hidden = YES;
//        btnWeather.hidden = YES;
//        btnCity.hidden = YES;
//        labelCity.hidden = YES;
//        labelTitle.hidden = NO;
//        labelTitle.text = @"更多";
//        
//        [btnHome setBackgroundImage:[UIImage imageNamed:@"首页_02"] forState:UIControlStateNormal];
//        [btnFind setBackgroundImage:[UIImage imageNamed:@"发现_02"] forState:UIControlStateNormal];
//        [btnMe setBackgroundImage:[UIImage imageNamed:@"我_02"] forState:UIControlStateNormal];
//        [btnMore setBackgroundImage:[UIImage imageNamed:@"更多_01"] forState:UIControlStateNormal];
//        
//        labelHome.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelFind.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMe.textColor = [UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1];
//        labelMore.textColor = [UIColor colorWithRed:0.55 green:0.77 blue:0.2 alpha:1];
//    }
//}

- (IBAction)weatherAction:(id)sender {

    HPActivityListViewController *mvc = [[HPActivityListViewController alloc]init];
    [self.navigationController pushViewController:mvc animated:YES];
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"test" object:nil];
}

- (IBAction)cityAction:(id)sender {
    DebugLog(@"cityAction");
    cityChangeFlag=YES;
    CityViewController *cityListVC = [[CityViewController alloc] init];
    cityListVC.delegate = self;
    [self.navigationController pushViewController:cityListVC animated:YES];
}

- (IBAction)enternYou:(id)sender {
    FindSpotViewController *vc = [[FindSpotViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];

}

- (IBAction)enternRoute:(id)sender {
    RouteShopViewController *vc = [[RouteShopViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)enternLP:(id)sender {
    LocalProductViewController *vc = [[LocalProductViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//delegate CitySelDelegate
- (void)cityButtonAction:(NSInteger) tag {
    
}

//切换城市
- (void)citySelAction:(NSDictionary *)city {
    self.isAllPark = YES;
    [self.parkChangeBtn setBackgroundImage:[UIImage imageNamed:@"allparks"] forState:UIControlStateNormal];
    [AppDelegate instance].dicCurrentCity = city;
    //[btnCity setTitle:[city objectForKey:@"cname"] forState:UIControlStateNormal];
    labelCity.text = [city objectForKey:@"cname"];
    //删除标注
    NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
    [_mapView removeAnnotations:array];
    [_clusterCaches removeAllObjects];
    for (NSInteger i = 3; i < 21; i++) {
        [_clusterCaches addObject:[NSMutableArray array]];
    }
    if(cityChangeFlag){
        GPSLocation = NO;//关闭定位
    }else{
        GPSLocation = YES;//关闭定位
    }
    
    [homeEntity.mutableArrayPark removeAllObjects];
    [homeEntity.mutableArrayFind removeAllObjects];
    [homeEntity.mutableArrayLP removeAllObjects];
    [homeEntity.mutableArrayRoute removeAllObjects];
    
    [self getHomeData:[city objectForKey:@"id"] RefreshView:nil];
    
    [self getWeatherData:[city objectForKey:@"cname"]];
    
    if ([[city objectForKey:@"cname"] isEqualToString:
        [[NSUserDefaults standardUserDefaults] valueForKey:SelectedCityName]] == NO) {
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:SelectedCityDifferent];
    } else {
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:SelectedCityDifferent];
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:[city objectForKey:@"cname"] forKey:SelectedCityName];
    [[NSUserDefaults standardUserDefaults] setObject:[city objectForKey:@"id"] forKey:SelectedCityId];
    _city_id = [city objectForKey:@"id"];
    [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:SelectedCurrentCity];
}

- (void)addHeader {
    //__unsafe_unretained OAAnnoViewController *vc = self;
    MJRefreshHeaderView *header = [MJRefreshHeaderView header];
    header.scrollView = self.scrollViewMain;
    
    header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
        // 进入刷新状态就会回调这个Block
        [homeEntity.mutableArrayPark removeAllObjects];
        [homeEntity.mutableArrayFind removeAllObjects];
        [homeEntity.mutableArrayLP removeAllObjects];
        [homeEntity.mutableArrayRoute removeAllObjects];
        
        _city_id = [[AppDelegate instance].dicCurrentCity objectForKey:@"id"];
        [self getHomeData:[[AppDelegate instance].dicCurrentCity objectForKey:@"id" ] RefreshView:refreshView];
        [self getWeatherData:[[AppDelegate instance].dicCurrentCity objectForKey:@"cname"]];
//        [self getWeatherData:@"北京"];
        NSLog(@"%@----开始进入刷新状态", refreshView.class);
    };
    header.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
        // 刷新完毕就会回调这个Block
        NSLog(@"%@----刷新完毕", refreshView.class);
    };
    header.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
        // 控件的刷新状态切换了就会调用这个block
        switch (state) {
            case MJRefreshStateNormal:
                NSLog(@"%@----切换到：普通状态", refreshView.class);
                break;
                
            case MJRefreshStatePulling:
                NSLog(@"%@----切换到：松开即可刷新的状态", refreshView.class);
                break;
                
            case MJRefreshStateRefreshing:
                NSLog(@"%@----切换到：正在刷新状态", refreshView.class);
                break;
            default:
                break;
        }
    };
    [header beginRefreshing];
    _header = header;
}

//-(IBAction)segmentAction:(UISegmentedControl *)Seg{
//    NSInteger Index = Seg.selectedSegmentIndex;
//    NSLog(@"Index %i", Index);
//    switch (Index) {
//        case 0:
//            findVC.view.hidden = NO;
//            findRecomVC.view.hidden = YES;
//            break;
//        case 1:
//            findVC.view.hidden = YES;
//            findRecomVC.view.hidden = NO;
//            break;
//        default:
//            break;
//    }
//}

- (void) handleNotification:(NSDictionary *)alertInfo {
    dicPushMessage = alertInfo;
    
    NSDictionary *aps = [alertInfo valueForKeyPath:@"aps"];
    NSString *message = [aps valueForKeyPath:@"alert"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"推送消息"
                                                    message:message
                                                   delegate:self
                                          cancelButtonTitle:@"忽略"
                                          otherButtonTitles:@"消息查看", nil];
    alert.tag = 11000;
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (alertView.tag == 11000) {
        if (buttonIndex == 1) {
            WebViewController *vc = [[WebViewController alloc] init];
            vc.url = [dicPushMessage valueForKeyPath:@"url"];
            vc.vcTitle = [dicPushMessage valueForKeyPath:@"title"];
            vc.imageShare = [UIImage imageNamed:@"icon-05 3"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    } else if (alertView.tag == 12000) {
        if (buttonIndex == 1) {
            NSString *cityTemp = [[NSUserDefaults standardUserDefaults] valueForKey:@"city"];
            NSString *city = [cityTemp stringByReplacingOccurrencesOfString:@"市" withString:@""];
            //取消市
            NSMutableArray *keys = [[NSMutableArray alloc] init];
            [keys addObjectsFromArray:[[[AppDelegate instance].cities allKeys] sortedArrayUsingSelector:@selector(compare:)]];
            for (int i = 0; i < [keys count]; i++) {
                NSString *key = [keys objectAtIndex:i];
                NSMutableArray *citys = [[AppDelegate instance].cities objectForKey:key];
                for (int j = 0; j < [citys count]; j++) {
                    NSDictionary *dic = [citys objectAtIndex:j];
                    NSString *city_name = [dic valueForKeyPath:@"cname"];
                    if ([city_name isEqualToString:city] == YES) {
                        [self citySelAction:dic];
                        return;
                    }
                }
            }
        } else {
            [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:SelectedCurrentCity];
        }
    } else if (alertView.tag == 90000) {
        if (buttonIndex == 1) {
            NSURL *url = [NSURL URLWithString:super.appURL];
            [[UIApplication sharedApplication]openURL:url];
        }
    }
    if (alertView.tag == 10001)
    {
        if (buttonIndex == 1) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    pageControlMenu.currentPage = (int)(menuScrollView.contentOffset.x / menuScrollView.frame.size.width);
}

- (void)locationUpdated {
    LocationManagement *lm = [LocationManagement sharedInstance];
    [lm performCoordinateGeocode:lm.location.coordinate
                         success:^(id responseObject) {
                             NSDictionary *placeCityDic = (NSDictionary *)responseObject;
                             lm.city = [placeCityDic objectForKey:@"City"];
                             
                             [[NSUserDefaults standardUserDefaults] setObject:lm.city forKey:@"city"];
                             [[NSUserDefaults standardUserDefaults] synchronize];
                             
                             NSString *city = [lm.city stringByReplacingOccurrencesOfString:@"市" withString:@""];
                             NSString *current_city = [[AppDelegate instance].dicCurrentCity valueForKeyPath:@"cname"];
                             NSString *select = [[NSUserDefaults standardUserDefaults] valueForKey:SelectedCurrentCity];
                             static int times = 0;
                             if((lm.city != nil || lm.city.length == 0) && times++ == 0
                                && [select isEqualToString:@"1"] == YES) {
                                 NSString *message = [NSString stringWithFormat:@"当前定位城市是 %@，是否要切换到当前城市", city];
                                 if ([city isEqualToString:current_city] == NO) {
                                     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"定位提示"
                                                                                     message:message
                                                                                    delegate:self
                                                                           cancelButtonTitle:@"取消"
                                                                           otherButtonTitles:@"确定", nil];
                                     alert.tag = 12000;
                                     [alert show];
                                 }
                             }
                             
                             NSString *lat = [NSString stringWithFormat:@"%f", lm.location.coordinate.latitude];
                             NSString *longitude = [NSString stringWithFormat:@"%f", lm.location.coordinate.longitude];
                             
                             [[NSUserDefaults standardUserDefaults] setObject:lat forKey:@"last_latitude"];
                             [[NSUserDefaults standardUserDefaults] setObject:longitude forKey:@"last_longitude"];
                             
                             [lm stopGPS];
                         } failure:^(NSError *error) {
                         }];
    DebugLog(@"locationUpdated = %@, %f, %f", lm.city, lm.location.coordinate.latitude, lm.location.coordinate.longitude);
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return (today==nil?0:1) + (forecast==nil?0:[forecast count]);
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *weatherTableViewCellIdentifier = K_cellIdentifier;
    weatherTableViewCell *cell = (weatherTableViewCell *)[tableView dequeueReusableCellWithIdentifier:weatherTableViewCellIdentifier];
    if (cell == nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:K_cellIdentifier owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    
    if (indexPath.row == 0 && today != nil) {
        
        cell.dateLabel.text = today.todayDate;
        
        NSString *imageURL = [NSString stringWithFormat:@"%@%@", IMAGE_URL, today.todayImage];
        [cell.weatherImage sd_setImageWithURL:[NSURL URLWithString:imageURL]];
        
        cell.weekLabel.text=today.todayWeek;
        
        cell.contenLabel.text = today.todayType;
        
        cell.from.text =today.todayLow;
        cell.to.text = today.todayHigh;
        
    } else {
    
        nextDays = [[FirstWeatherEntity alloc]initWithAttributes:forecast[indexPath.row-1]];
        cell.dateLabel.text = nextDays.weatherDate;
        NSString *imageURL = [NSString stringWithFormat:@"%@%@", IMAGE_URL, nextDays.weatherImage];
        [cell.weatherImage sd_setImageWithURL:[NSURL URLWithString:imageURL]];
        cell.weekLabel.text = nextDays.weatherWeek;
        cell.contenLabel.text = nextDays.weatherType;
        cell.from.text =nextDays.weatherLow;
        cell.to.text = nextDays.weatherHigh;
    
    }
    
    return cell;
}

-(void)disappear
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.2];
    weatherTableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200);
    [UIView commitAnimations];
    blackAlpha.frame = CGRectMake(0, ScreenHeight, self.view.bounds.size.width, self.view.bounds.size.height);
    self.tabBarController.tabBar.hidden =NO;
    
}

-( void )dealloc
{
    // 移除通知
    [[ NSNotificationCenter defaultCenter ] removeObserver : self ];
    if (_mapView) {
        _mapView = nil;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"WrapperMainViewController"];
    
//    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _locService.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
//    /**
//     *  保存图片到本地
//     */
//    for (int i = 0; i < self.buttonArr.count; i++) {
//        UIButton *button = self.buttonArr[i];
//        [self imageSavedToCache:[button imageForState:UIControlStateNormal] andImageName:self.imageNameArr[i]];
//    }
    
    
    [MobClick endLogPageView:@"WrapperMainViewController"];
    
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
    _locService.delegate = nil;
}


//更新聚合状态
- (void)updateClusters {
    _clusterZoom = (NSInteger)_mapView.zoomLevel;
    @synchronized(_clusterCaches) {
        __block NSMutableArray *clusters = [_clusterCaches objectAtIndex:(_clusterZoom - 3)];
        
        if (clusters.count > 0) {
            [_mapView removeAnnotations:_mapView.annotations];
            [_mapView addAnnotations:clusters];
        } else {
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                ///获取聚合后的标注
                __block NSArray *array = [_clusterManager getClusters:_clusterZoom];
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    for (int i=0;i<[array count];i++) {
                        BMKCluster *item=array[i];
                        ClusterAnnotation *annotation = [[ClusterAnnotation alloc] init];
                        annotation.coordinate = item.coordinate;
                        annotation.size = item.size;
                        annotation.parksArray = item.clusterItems;
                        ParkEntity *entity = nil;//homeEntity.mutableArrayPark[i];
                        int k;
                        for(k=0;k<[homeEntity.mutableArrayPark count];k++){
                            ParkEntity *entityTemp=homeEntity.mutableArrayPark[k];
                            if([entityTemp.title isEqualToString:item.name]==YES){
                                entity = entityTemp;
                                break;
                            }
                        }
                        annotation.title = [NSString stringWithFormat:@"%d",k];
                        annotation.subtitle = entity.album_thumb;
                        [clusters addObject:annotation];
                    }
                    
                    [_mapView removeAnnotations:_mapView.annotations];
                    [_mapView addAnnotations:clusters];
                    
                    if(!GPSLocation){
                        if(setMapCenter==YES && [homeEntity.mutableArrayPark count]>0){
                            ParkEntity *entity = homeEntity.mutableArrayPark[0];
                            CLLocation *location = [[CLLocation alloc] initWithLatitude:[entity.latitude doubleValue] longitude:[entity.longitude doubleValue]];
                            [_mapView setCenterCoordinate:location.coordinate animated:NO];
                            setMapCenter=NO;
                            _mapView.zoomLevel=mapZoomLevel;
                        }
                    }else{
                        [_mapView setCenterCoordinate:_autoLocation.location.coordinate animated:YES];
                        GPSLocation = NO;
                    }
                });
            });
        }
    }
}

#pragma mark - BMKMapViewDelegate 
// 根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    //普通annotation
    NSString *AnnotationViewID = @"ClusterMark";
    ClusterAnnotation *cluster = (ClusterAnnotation*)annotation;
    ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
    annotationView.size = cluster.size;
    annotationView.canShowCallout = NO;//在点击大头针的时候会弹出那个黑框框
    annotationView.draggable = NO;//禁止标注在地图上拖动
    annotationView.annotation = cluster;
//    annotationView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]];
    annotationView.centerOffset=CGPointMake(0,-80);
    
    UIView *viewForImage=[[UIView alloc]init];
    UIImageView *imageview=[[UIImageView alloc]init];
    if(iPhone6Plus){
        [viewForImage setFrame:CGRectMake(0, 0, 225, 225)];
        [imageview setFrame:CGRectMake(0, 0, 225, 225)];
    }else{
        [viewForImage setFrame:CGRectMake(0, 0, 150, 150)];
        [imageview setFrame:CGRectMake(0, 0, 150, 150)];
    }
    //同步加载
//    [imageview setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]];
    //异步加载
//    [imageview sd_setImageWithURL:[NSURL URLWithString:annotation.subtitle] placeholderImage:[UIImage imageNamed:@"placehodeLoading.png"]];

    [imageview sd_setImageWithURL:[NSURL URLWithString:annotation.subtitle] placeholderImage:[UIImage imageNamed:@"placehodeLoading.png"] options:SDWebImageLowPriority | SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
     {
         annotationView.image=[self getImageFromView:viewForImage];//修改默认图片不替换问题
     }];
    
    imageview.layer.masksToBounds=YES;
     imageview.layer.cornerRadius = 10;
     [viewForImage addSubview:imageview];
     annotationView.image=[self getImageFromView:viewForImage];
    if([homeEntity.mutableArrayPark count]>0){
        int index = [cluster.title intValue];
        ParkEntity *entity = homeEntity.mutableArrayPark[index];
        annotationView.labelTitle.text = entity.title;
    }
    return annotationView;
}

-(UIImage *)getImageFromView:(UIView *)view{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

/**
 *当点击annotation view弹出的泡泡时，调用此接口
 *@param mapView 地图View
 *@param view 泡泡所属的annotation view
 */
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view {
    if ([view isKindOfClass:[ClusterAnnotationView class]]) {
        ClusterAnnotation *clusterAnnotation = (ClusterAnnotation*)view.annotation;
        if (clusterAnnotation.size > 1) {
            [mapView setCenterCoordinate:view.annotation.coordinate];
            [mapView zoomIn];
        }
    }
}

/**
 *地图初始化完毕时会调用此接口
 *@param mapview 地图View
 */
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView {
    [self updateClusters];
}

/**
 *地图渲染每一帧画面过程中，以及每次需要重绘地图时（例如添加覆盖物）都会调用此接口
 *@param mapview 地图View
 *@param status 此时地图的状态
 */
- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status {
    if (_clusterZoom != 0 && _clusterZoom != (NSInteger)mapView.zoomLevel) {
        [self updateClusters];
    }
}

- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view {
   if ([view isKindOfClass:[ClusterAnnotationView class]]) {
        ClusterAnnotation *clusterAnnotation = (ClusterAnnotation*)view.annotation;
        if (clusterAnnotation.size > 1) {
            ParkTableViewController *parksListVC = [ParkTableViewController new];
            parksListVC.parksArray = clusterAnnotation.parksArray;
            [self.navigationController pushViewController:parksListVC animated:YES];
//            [mapView setCenterCoordinate:view.annotation.coordinate];
//            [mapView zoomIn];
        }else {
            ParkEntity *entity = [homeEntity.mutableArrayPark objectAtIndex:[clusterAnnotation.title integerValue]];
            if ([entity.is_business isEqualToString:@"0"] == YES) {
                IntroduceViewController *vc = [[IntroduceViewController alloc] init];
                vc.parkId = [NSString stringWithFormat:@"%@",entity.ID];
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                WrapperViewController *vc = [[WrapperViewController alloc] init];
                vc.parkEntity = entity;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
    }
 [_mapView deselectAnnotation:view.annotation animated:YES];
}

- (IBAction)zoomBig:(id)sender {
    if (_mapView.zoomLevel++ > 18 ) {
        return;
    }
    [_mapView zoomIn];
}

- (IBAction)zoomSmall:(id)sender {
    if (_mapView.zoomLevel-- < 4) {
        return;
    }
    [_mapView zoomOut];
}

- (IBAction)showLocation:(id)sender {
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        ALERT_ERR_MSG(LocationOpenTip);
    }else{
    GPSLocation = YES;//开启定位
    cityChangeFlag = NO;
    
    LocationManagement *lm = [LocationManagement sharedInstance];
    [lm performCoordinateGeocode:lm.location.coordinate
                         success:^(id responseObject) {
                             NSDictionary *placeCityDic = (NSDictionary *)responseObject;
                             lm.city = [placeCityDic objectForKey:@"City"];
                             
                             [[NSUserDefaults standardUserDefaults] setObject:lm.city forKey:@"city"];
                             [[NSUserDefaults standardUserDefaults] synchronize];
                             
                             NSString *city = [lm.city stringByReplacingOccurrencesOfString:@"市" withString:@""];
                             
                                     //取消市
                                     NSMutableArray *keys = [[NSMutableArray alloc] init];
                                     [keys addObjectsFromArray:[[[AppDelegate instance].cities allKeys] sortedArrayUsingSelector:@selector(compare:)]];
                                     for (int i = 0; i < [keys count]; i++) {
                                         NSString *key = [keys objectAtIndex:i];
                                         NSMutableArray *citys = [[AppDelegate instance].cities objectForKey:key];
                                         for (int j = 0; j < [citys count]; j++) {
                                             NSDictionary *dic = [citys objectAtIndex:j];
                                             NSString *city_name = [dic valueForKeyPath:@"cname"];
                                             if ([city_name isEqualToString:city] == YES) {
                                                 [self citySelAction:dic];
                                                 return;
                                             }
                                         }
                                     
                                 }
                         } failure:^(NSError *error) {
                         }];
    }
//    CLLocation *location = [[CLLocation alloc] initWithLatitude:[LocationManagement sharedInstance].location.coordinate.latitude
//                                                      longitude:[LocationManagement sharedInstance].location.coordinate.longitude
//];
//    [_mapView setCenterCoordinate:location.coordinate animated:YES];
    
//    //显示用户当前位置
//    dispatch_queue_t concurrentQueue = dispatch_queue_create("my.concurrent.queue", DISPATCH_QUEUE_CONCURRENT);
//    dispatch_sync(concurrentQueue, ^{
//        _mapView.showsUserLocation = YES;
//        [_mapView updateLocationData:_autoLocation];
//        [_mapView setCenterCoordinate:_autoLocation.location.coordinate animated:YES];
//    });
}

//处理方向变更信息
-(void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
//    NSLog(@"heading is %@", userLocation.heading);
    [_mapView updateLocationData:userLocation];
}

//处理位置坐标变更
-(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
//    NSLog(@"update user location");
    _autoLocation = userLocation;
    _mapView.showsUserLocation = YES;//显示定位图层
    [_mapView updateLocationData:userLocation];
//    [_mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}

-(void)shareCopy
{
    if ([AppDelegate instance].alreadyLunch) {
        return;
    }
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    NSString *coppedString = [[UIPasteboard generalPasteboard] valueForPasteboardType:[UIPasteboardTypeListString objectAtIndex:0] ];
    if (coppedString) {
        UserEntity *userEntity = [UserEntity sharedInstance];
        
        if (userEntity.login == YES) {
            if ([coppedString containsString:userEntity.nickName]) {
                return;
            }
        }
        if ([coppedString containsString:@"乐游口令#"]) {
            NSRange range =  [coppedString rangeOfString:@"进群口令"];
            NSRange range2 = [coppedString rangeOfString:@"】"];
            NSRange range3 = NSMakeRange((range.location +range.length), (range2.location - range.location -range.length));
            NSString * room_id = [coppedString substringWithRange:range3];
            [[UIPasteboard generalPasteboard] setValue:@"" forPasteboardType:[UIPasteboardTypeListString objectAtIndex:0]];
            EnterShareViewController *vc = [[EnterShareViewController alloc] init];
            vc.room_id = room_id;
            UINavigationController *nav =[[UINavigationController alloc] initWithRootViewController:vc];
            
            [self presentViewController:nav animated:YES completion:nil];
            
        }
        
    }
    
}

- (NSMutableArray *)buttonArr {
    if (!_buttonArr) {
        _buttonArr = [[NSMutableArray alloc]init];
    }
    return _buttonArr;
}

- (NSMutableArray *)imageNameArr {
    if (!_imageNameArr) {
        _imageNameArr = [[NSMutableArray alloc]init];
    }
    return _imageNameArr;
}




@end